/* eslint-disable no-console */
/* eslint-disable class-methods-use-this */

import { TioCommand } from '../types';
import { tioSend } from '../utils/TioSend';

export default class TioHandler {
  protected closed = false;

  onOpen(event: Event): void {
    console.log('WebSocket connection opened', event);
  }

  onMessage(event: MessageEvent): void {
    console.log('WebSocket message received:', event.data);
  }

  onClose(event: CloseEvent): void {
    this.closed = true;
    console.log('WebSocket connection closed', event);
  }

  onError(event: Event): void {
    console.error('WebSocket error occurred', event);
  }

  ping(): void {
    tioSend(TioCommand.HeartbeatReq, null);
  }
}
